package cn.zyy.service;

import cn.zyy.dao.*;
import cn.zyy.entity.Course;
import cn.zyy.entity.Score;
import cn.zyy.entity.Student;

import java.util.List;

/**
 * 成绩业务层
 */
public class ScoreServiceImpl implements ScoreService {
    private ScoreDao scoreDao = new ScoreDaoImpl();
    private StudentDao studentDao = new StudentDaoImpl();
    private CourseDao courseDao = new CourseDaoImpl();

    @Override
    //根据学生姓名、科目名称和分数给学生记录成绩
    public Boolean addScore(String stuName, String courseName, Double score) {
        //1、根据学生姓名查询学生ID
        Student student = studentDao.selectId(stuName);
        //2、根据科目名称查询科目ID
        Course course = courseDao.findCourseByCourseName(courseName);
        //插入成绩
        return scoreDao.addScore(student.getStuId(), course.getCourseId(), score) > 0;
    }

    @Override
    //查询指定科目的所有学生的成绩
    public List<Score> findAllScore(String courseName) {
        return scoreDao.findAllScores(courseName);
    }

}
